/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.knezevic.realestate.pages;

import com.knezevic.realestate.Identifiable;
import com.knezevic.realestate.Member;
import com.knezevic.realestate.beans.MemberBean;
import com.knezevic.realestate.service.Members;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

/**
 *
 * @author Nemanja
 */
public class EditProfile {
    @Inject
    private Members members;
    @Property
    private Member memberBean;
    @Persist("flash")
    @Property
    private String message;

     public void onActivate(long id) {
        memberBean = members.retrieve(id);
    }

    public long onPassivate(){
        return Identifiable.class.cast(memberBean).getID();
    }

    Object onActionFromLogout(){
        return Login.class;
    }

    Object onSuccess(){
        message = "You have successfully changed your personal data!";
        return null;
    }
    Object onSubmitFromMemberBean(){
        members.update(memberBean);
        return  null;
    }
    public void setMember(Member member){
        this.memberBean = (MemberBean) member;
    }
    Object onActionFromProfile(String username){
       return null;
    }

    public long getID(){
        return Identifiable.class.cast(memberBean).getID();
    }
}
